import { useNavigate } from "./hooks";

export default function Link({ to, children }) {
  const navigate = useNavigate();

  const handleClick = (e) => {
    e.preventDefault(); // 禁止默认行为
    navigate(to); // 手动跳转
  };

  // 默认a链接点击会刷新整个页面
  return (
    <a href={to} onClick={handleClick}>
      {children}
    </a>
  );
}
